
typedef struct QueueNode{
    int val;
    struct QueueNode* next;
} QueueNode;


typedef struct {
    QueueNode* head;
    QueueNode* tail;
    int size;
} MyStack;


MyStack* myStackCreate() {
    MyStack* obj = (MyStack*) malloc( sizeof(MyStack) );
    obj->head = NULL;
    obj->tail = NULL;
    obj->size = 0;
    return obj;
}

void myStackPush(MyStack* obj, int x) {
    QueueNode* node = (QueueNode*) malloc( sizeof(QueueNode) );
    node->val = x;
    if(obj->size == 0){
        obj->head = obj->tail = node;
    }else{
        node->next = obj->head;
        obj->head = node;
    }

    (obj->size)++;
}

int myStackPop(MyStack* obj) {
    QueueNode* node = obj->head;
    (obj->size)--;
    obj->head = obj->head->next;
    return node->val;
}

int myStackTop(MyStack* obj) {
    return obj->head->val;
}

bool myStackEmpty(MyStack* obj) {
    return obj->size == 0;
}

void myStackFree(MyStack* obj) {
    free(obj);
}
